package com.ruoyi.web.controller.settlement;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.domain.AmProject;
import com.ruoyi.settlement.domain.AmSettlement;
import com.ruoyi.settlement.domain.AmSettlementVo;
import com.ruoyi.settlement.service.IAmSettlementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 结算单管理Controller
 * 
 * @author ruoyi
 * @date 2020-07-29
 */
@RestController
@RequestMapping("/settlement/settlement")
@Api(description = "结算单管理")
public class AmSettlementController extends BaseController
{
    @Autowired
    private IAmSettlementService amSettlementService;

    /**
     * 查询结算单管理列表
     */
    @PreAuthorize("@ss.hasPermi('settlement:settlement:list')")
    @GetMapping("/list")
    @ApiOperation("查询结算单管理列表")
    public TableDataInfo list(AmSettlementVo amSettlement)
    {
        startPage();
        List<AmSettlementVo> list = amSettlementService.selectAmSettlementList(amSettlement);
        return getDataTable(list);
    }

    /**
     * 导出结算单管理列表
     */
    @PreAuthorize("@ss.hasPermi('settlement:settlement:export')")
    @Log(title = "结算单管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出结算单管理列表")
    public AjaxResult export(AmSettlementVo amSettlement)
    {
        List<AmSettlementVo> list = amSettlementService.selectAmSettlementList(amSettlement);
        ExcelUtil<AmSettlementVo> util = new ExcelUtil<AmSettlementVo>(AmSettlementVo.class);
        return util.exportExcel(list, "settlement");
    }

    /**
     * 获取结算单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('settlement:settlement:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取结算单管理详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(amSettlementService.selectAmSettlementById(id));
    }

    /**
     * 新增结算单管理
     */
    @PreAuthorize("@ss.hasPermi('settlement:settlement:add')")
    @Log(title = "结算单管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增结算单管理")
    public AjaxResult add(@RequestBody AmSettlement amSettlement)
    {
        return toAjax(amSettlementService.insertAmSettlement(amSettlement));
    }

    /**
     * 修改结算单管理
     */
    @PreAuthorize("@ss.hasPermi('settlement:settlement:edit')")
    @Log(title = "结算单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改结算单管理")
    public AjaxResult edit(@RequestBody AmSettlement amSettlement)
    {
        return toAjax(amSettlementService.updateAmSettlement(amSettlement));
    }

    /**
     * 删除结算单管理
     */
    @PreAuthorize("@ss.hasPermi('settlement:settlement:remove')")
    @Log(title = "结算单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除结算单管理")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(amSettlementService.deleteAmSettlementByIds(ids));
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<AmSettlement> util = new ExcelUtil<AmSettlement>(AmSettlement.class);
        return util.importTemplateExcel("结算单数据");
    }

    /**
     * 查看审核情况
     */
    @GetMapping("/getAuditSituation")
    @ApiOperation("查看审核情况")
    public AjaxResult getAuditSituation(){
        return AjaxResult.success(amSettlementService.getAuditSituation());
    }
}
